import db from '../core/db';

class settingHelper {
  private _autoDelete: boolean = true;

  get autoDelete() {
    return this._autoDelete;
  }

  set autoDelete(autoDelete: boolean) {
    this._autoDelete = autoDelete;
    db.instance.update('autoDelete', autoDelete);
  }

  private _autoInstall: boolean = true;

  get autoInstall() {
    return this._autoInstall;
  }

  set autoInstall(autoInstall: boolean) {
    this._autoInstall = autoInstall;
    db.instance.update('autoInstall', autoInstall);
  }

  private _networkDl: boolean = false;

  get networkDl() {
    return this._networkDl;
  }

  set networkDl(networkDl: boolean) {
    this._networkDl = networkDl;
    db.instance.update('networkDl', networkDl);
  }

  private _notifyEnable: boolean = false;

  get notifyEnable() {
    return this._notifyEnable;
  }

  set notifyEnable(notifyEnable: boolean) {
    this._notifyEnable = notifyEnable;
    db.instance.update('notifyEnable', notifyEnable);
  }

  init() {
    db.instance.query('autoDelete').then((res) => {
      if (typeof res === 'boolean')
        this._autoDelete = res;
      else
        this._autoDelete = false;
    });
    db.instance.query('autoInstall').then((res) => {
      if (typeof res === 'boolean')
        this._autoInstall = res;
      else
        this._autoInstall = false;
    });
    db.instance.query('networkDl').then((res) => {
      if (typeof res === 'boolean')
        this._networkDl = res;
      else
        this._networkDl = false;
    });
    db.instance.query('notifyEnable').then((res) => {
      if (typeof res === 'boolean')
        this._notifyEnable = res;
      else
        this._notifyEnable = false;
    });
  }
}
export default new settingHelper();